package com.campus.mapper;

import com.campus.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * @author TaiZai
 * @data 2024/10/21 17:23
 */
@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询管理员
     * @param username
     * @return
     */
    @Select("select * from users where username = #{username}")
    User getByUsername(String username);

    /**
     * 注册
     * @param newUser
     */
    @Insert("insert into users (username, password, phone, email, role_id, status) " +
            "values (#{username}, #{password}, #{phone}, #{email}, 1, #{status})")
    void insert(User newUser);

    @Select("select * from users where phone = #{phone}")
    User getByPhone(String phone);

    /**
     * 新增用户
     * @param user
     */
    @Insert("insert into users (username, password, phone, email, role_id, create_time, update_time, status) " +
            "values (#{username}, #{password}, #{phone}, #{email}, #{roleId}, #{createTime}, #{updateTime}, #{status})")
    void addUser(User user);
}
